package com.zdd.ehe.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zdd.ehe.entity.DiseaseData;
import com.zdd.ehe.entity.ProvincePest;
import com.zdd.ehe.entity.Role;
import com.zdd.ehe.mapper.ProvincePestMapper;
import com.zdd.ehe.service.ProvincePestService;
import com.zdd.ehe.vo.ProvincePestVOByYear;
import com.zdd.ehe.vo.ProvincePestVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.Year;
import java.util.List;

/**
 * @version 1.0.0
 * @title: ProvincePestServiceImpl
 * @author: HFLy
 * @description:
 * @date: 6/3/2023 下午3:02
 */
@Service
public class ProvincePestServiceImpl extends ServiceImpl<ProvincePestMapper, ProvincePest> implements ProvincePestService {
    @Autowired
    private ProvincePestMapper provincePestMapper;
    @Override
    public List<ProvincePestVo> show(String type) {
        return provincePestMapper.show(type);
    }

    /**
     * 分页查询各省份病虫害损失数据列表
     *
     * @param page
     * @return
     */
    @Override
    public Page<ProvincePest> getAllProvincePestByPage(Page<ProvincePest> page) {
        Page<ProvincePest> pagex = provincePestMapper.getAllProvincePestByPage(page);
        return pagex;
    }

    @Override
    public List<ProvincePestVOByYear> getProvincePestByYear(Year year) {
        return provincePestMapper.getProvincePestByYear(year);
    }

    /**
     * 查询各年某种病虫害造成的损失
     *
     * @param disease
     * @return
     */
    @Override
    public List<ProvincePestVOByYear> getProvincePestByDisease(String disease) {
        return provincePestMapper.getProvincePestByDisease(disease);
    }

    /**
     * 新增病虫害数据损失信息
     * @param provincePest
     * @return
     */
    @Override
    public int addProvincePest(ProvincePest provincePest) {
        int result = -1;
        try {
            result = provincePestMapper.insert(provincePest);
        }catch (Exception e){
            e.printStackTrace();
        }
        return result;
    }

    @Override
    public int update(ProvincePest provincePest) {
        int result = -1;
        try{
            result = provincePestMapper.updateById(provincePest);
        }catch (Exception e){
            e.printStackTrace();
        }
        return result;
    }


}
